/*
 * PrintTable.cpp
 *
 *  Created on: 15/12/2009
 *      Author: luis
 */

#include "PrintTable.h"
#include "PangoWindow.h"

PrintTable::PrintTable(Circuito* circuito){
	this->circuito = circuito;
}

Glib::RefPtr<PrintTable> PrintTable::create(Circuito* circuito){
	return Glib::RefPtr<PrintTable>(new PrintTable(circuito));
}

void PrintTable::on_begin_print(
        const Glib::RefPtr<Gtk::PrintContext>& print_context){
	set_n_pages(1);
}


void PrintTable::on_draw_page(const Glib::RefPtr<Gtk::PrintContext>& print_context, int page_nr){
	if (circuito->circuito_listo()){
		Cairo::RefPtr<Cairo::Context> cairo_ctx = print_context->get_cairo_context();
		float x = print_context->get_width();
		float y = print_context->get_height();
		PangoWindow salida(this->circuito, this->circuito->simular());
		cairo_ctx->save();
		float alto = (pow (2, circuito->get_lista_entradas().size()) + 2)*(TAMANIO_FILA);
		float ancho = ((circuito->get_lista_entradas().size() + circuito->get_lista_salidas().size())*TAMANIO_COLUMNA)+50;
		float x_scala = x / ancho;
		float y_scala = y / (alto);
		cairo_ctx->scale(x_scala,y_scala);
		cairo_ctx->move_to(0,0);
		salida.pintar_en_ventana(cairo_ctx);
		cairo_ctx->restore();
	}
}

PrintTable::~PrintTable(){

}
